package com.hmall.item.web;

import com.hmall.common.dto.PageDTO;
import com.hmall.item.pojo.Item;
import com.hmall.item.service.IItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("item")
public class ItemController {
    @Autowired
    private IItemService itemService;
    //分页查询
    @GetMapping("list")
    public PageDTO<Item> list(@RequestParam(value = "page",required = false) Integer page,
                              @RequestParam(value = "size",required = false) Integer size
                        ){
        PageDTO<Item> pageDTO =itemService.listPage(page,size);
        return pageDTO;
    }
    //根据id查询商品
    @GetMapping("{id}")
    public Item list(@PathVariable("id")Long id ){
        Item item =itemService.findItemById(id);
        return item;
    }
    //新增数据
    @PostMapping
    public void add(@RequestBody Item item){
        itemService.add(item);
    }

    //上xia架
    @PutMapping("/status/{id}/{status}")
    public void shangjia(@PathVariable("id") Long id,
                            @PathVariable("status") Integer status){
        itemService.sahngxiajia(id,status);

    }

    //修改商品
    @PutMapping
    public void update(@RequestBody Item item){
        itemService.updatee(item);
    }
    //删除商品
    @DeleteMapping("{id}")
    public void deletee(@PathVariable("id") Long id){
        itemService.deletete(id);
    }
}
